package com.doyens.gmall.product.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.R;
import com.doyens.gmall.common.result.Result;
import com.doyens.gmall.model.product.*;
import com.doyens.gmall.product.service.SpuManageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Classname:SpuManageController
 * PackageName:com.doyens.gmall.product.controller
 *
 * @Author:uyijk
 * @Create:2023/7/26 14:27
 * @Version: 1.0
 */
@RestController
@RequestMapping("admin/product")
@Api(tags = "spu管理")
public class SpuManageController {

    @Autowired
    private SpuManageService spuManageService;
    @ApiOperation(value = "分页查询spu信息")
    @GetMapping("{page}/{size}")
    public Result getSpuInfoPage(@PathVariable("page")Long page,@PathVariable("size")Long size,Long category3Id){
        IPage<SpuInfo> spuInfoIPage = spuManageService.getSpuInfoPage(page,size,category3Id);
        return Result.ok(spuInfoIPage);
    }

    @ApiOperation("获取所有销售属性")
    @GetMapping("baseSaleAttrList")
    public Result baseSaleAttrList(){
        List<BaseSaleAttr> saleAttrList = spuManageService.getBaseSaleAttrList();
        return Result.ok(saleAttrList);
    }

    @ApiOperation("保存spu信息")
    @PostMapping("saveSpuInfo")
    public Result saveSpuInfo(@RequestBody SpuInfo spuInfo){
        spuManageService.saveSpuInfo(spuInfo);
        return Result.ok();
    }

    @ApiOperation("根据spuId获取所有图片")
    @GetMapping("spuImageList/{spuId}")
    public Result spuImageList(@PathVariable("spuId")Long spuId){
        List<SpuImage> spuImageList = spuManageService.getSpuImageList(spuId);
        return Result.ok(spuImageList);
    }

    @GetMapping("spuSaleAttrList/{spuId}")
    public Result spuSaleAttrList(@PathVariable("spuId")Long spuId){
        List<SpuSaleAttr> spuSaleAttrList = spuManageService.getSpuSaleAttrList(spuId);
        return Result.ok(spuSaleAttrList);
    }

}
